package bb.lanxing.chart.sample.result;

import com.baidu.mapapi.model.LatLng;

import java.util.ArrayList;
import java.util.List;

import bb.lanxing.chart.sample.result.i.ISportMapPointSampleResult;
import bb.lanxing.model.database.IRouteBookPoint;
import bb.lanxing.nav.NavServiceManager;
import bb.lanxing.util.DistanceUtil;
import bb.lanxing.util.PolyUtil;

public class SportMapPointSampleResult implements ISportMapPointSampleResult<IRouteBookPoint> {
    private List<Double> distanceList;
    private Double maxAltitude;
    private Double minAltitude;
    private List<IRouteBookPoint> sampleDataSourceList;

    public void setDistanceList(List<Double> list) {
        this.distanceList = list;
    }

    public void setSampleDataSourceList(List<IRouteBookPoint> list) {
        this.sampleDataSourceList = list;
    }

    public void setMaxAltitude(Double d) {
        this.maxAltitude = d;
    }

    public void setMinAltitude(Double d) {
        this.minAltitude = d;
    }

    @Override
    public List<Double> getSampledDistance() {
        return this.distanceList;
    }

    @Override
    public List<IRouteBookPoint> getSampleDataSource() {
        return this.sampleDataSourceList;
    }

    @Override
    public double getMaxAltitude() {
        return this.maxAltitude;
    }

    @Override
    public double getMinAltitude() {
        return this.minAltitude;
    }

    @Override
    public int getUserInlushuLocation(LatLng latLng) {
        ArrayList arrayList = new ArrayList();
        List<IRouteBookPoint> sampleDataSource = getSampleDataSource();
        List<Double> sampledDistance = getSampledDistance();
        int i = 0;
        for (int i2 = 0; i2 < sampleDataSource.size(); i2++) {
            IRouteBookPoint iRouteBookPoint = sampleDataSource.get(i2);
            arrayList.add(iRouteBookPoint.getLatLng());
            iRouteBookPoint.setDistance(sampledDistance.get(i2));
        }
        if (PolyUtil.isLocationOnEdge(latLng, arrayList, true, 50.0d) && NavServiceManager.getInstance().isNavigating()) {
            LatLng latLng2 = (LatLng) arrayList.get(0);
            double d = DistanceUtil.get(latLng.latitude, latLng.longitude, latLng2.latitude, latLng2.longitude);
            int i3 = 1;
            while (i3 < arrayList.size()) {
                LatLng latLng3 = (LatLng) arrayList.get(i3);
                double d2 = DistanceUtil.get(latLng.latitude, latLng.longitude, latLng3.latitude, latLng3.longitude);
                if (d < d2) {
                    i = i3;
                } else {
                    i3++;
                    i = i3;
                    d = d2;
                }
                i3++;
            }
        }
        return i;
    }
}